package com.demo.di;

import com.demo.ioc.UserService;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

import java.util.HashMap;
import java.util.Map;

public class testDI {
    
    @Test
    public void test() {
        String xmlConfig="beans.xml";
        ApplicationContext applicationContext=new  ClassPathXmlApplicationContext(xmlConfig);
        BookService bookService= (BookService) applicationContext.getBean("bookServiceId");
        bookService.addBook();
    }
    
    @Test
    public void test1() {
        String xmlConfig="beans.xml";
        BeanFactory beanFactory=new XmlBeanFactory(new ClassPathResource(xmlConfig));
        BookService bookService= (BookService) beanFactory.getBean("bookServiceId");
        bookService.addBook();
    }
}
